package com.bungarus.config;


import com.bungarus.Access;
import com.bungarus.busi.*;
import io.netty.channel.socket.SocketChannel;

/**
 * Created by tang on 2018/11/11.
 */
public class ChannelAccessInitializer extends ChannelServerInitializer {
    private final Access access;

    public ChannelAccessInitializer(Access access) {
        this.access = access;
    }

    @Override
    protected void initNormalHandlers(SocketChannel socketChannel) {
        if(Access.PORT_8080 == socketChannel.localAddress().getPort() ||
                Access.PORT_80 == socketChannel.localAddress().getPort()) {
            socketChannel.pipeline().addLast(new ServerAuthHandler());
            socketChannel.pipeline().addLast(new CreateSessionHandler());
            socketChannel.pipeline().addLast(new TransferSessionHandler(access));
            socketChannel.pipeline().addLast(new AuthResponseHandler());
            socketChannel.pipeline().addLast(new ClientMessageRequestHandler(access));
        }
    }

    @Override
    protected void initServerServiceHandlers(SocketChannel socketChannel) {
        if(Access.PORT_7700 == socketChannel.localAddress().getPort() ||
                Access.PORT_7800 == socketChannel.localAddress().getPort()){
            socketChannel.pipeline().addLast(new ServerMediaHandler());
        }
    }
}
